﻿using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Text;

namespace Wfxin.SystemFramework.Attributes
{
    /// <summary>
    /// 异常过滤器
    /// 详见：https://www.cnblogs.com/liqingwen/p/8585119.html
    /// </summary>
    public class TikuExceptionFilterAttribute: Attribute, IExceptionFilter
    {
         
        private readonly ILogger<TikuExceptionFilterAttribute> _Logger = null;

        public TikuExceptionFilterAttribute(ILoggerFactory loggerFactory)
        {
            _Logger = loggerFactory.CreateLogger<TikuExceptionFilterAttribute>();
        }

        public void OnException(ExceptionContext context)
        {
            _Logger.LogError(context.Exception, "异常过滤器捕获到系统异常");
            context.ExceptionHandled = true;
        }

    }
}
